//
//  ZKJPresentationVC.swift
//  SinaWeiBo
//
//  Created by ZKJ on 2017/8/29.
//  Copyright © 2017年 ZKJ. All rights reserved.
//

import UIKit

class ZKJPresentationVC: UIPresentationController {
    
    // MARK:- 对外提供的属性
    var presentedFrame : CGRect = CGRect.zero
    
    // MARK:- 懒加载属性
    fileprivate lazy var coverView : UIView = UIView()
    
    // MARK:- 系统回调函数
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        
        // 1.设置弹出view的尺寸
        presentedView?.frame = presentedFrame
        
        // 2.添加蒙板
        setUpCoverView()
    }
    
}

extension ZKJPresentationVC {
    fileprivate func setUpCoverView() {
        
        // 1.添加蒙板
        containerView?.insertSubview(coverView, at: 0)
        coverView.backgroundColor = UIColor(white: 0.8, alpha: 0.5)
        coverView.frame = containerView!.bounds
        
        // 2.添加手势
        let tapGes = UITapGestureRecognizer(target: self, action: #selector(ZKJPresentationVC.tapClick))
        coverView.addGestureRecognizer(tapGes)
    }
}

// MARK:- 手势事件的监听
extension ZKJPresentationVC {
    @objc fileprivate func tapClick() {
        print("tapClick")
        presentedViewController.dismiss(animated: true, completion: nil)
    }
}
